package com.haredot.entity;

import java.time.LocalDate;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Student implements User{
    /**
    * 学生学号
    */
    @NotNull(message = "学号不允许为空")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    @NotEmpty(message = "密码不允许为空")
    private String password ;
    /**
    * 姓名
    */
    @NotEmpty(message = "型名不允许为空")
    private String name;

    /**
    * 班级名
    */
    @NotEmpty(message = "班级名不允许为空")
    private String className;

    /**
    * 性别
    */
    @NotEmpty(message = "性别不允许为空")
    private String sex;

    /**
    * 出生日期
    */
    @NotNull(message = "出生日期不允许为空")
    @Past(message = "出生日期必须是一个过去时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate birthday;

    /**
    * 专业
    */
    @NotEmpty(message = "专业不允许为空")
    private String major;

    /**
     * 选修的课程
     */
    private String courseNames ;

    @Override
    public Long getUsername() {
        return this.id;
    }

    @Override
    public String getRole() {
        return "student";
    }
}